package com.zj.syzs.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.zj.shouyou.R;
import com.zj.syzs.config.UrlConfig;
import com.zj.syzs.fragment.MICommentFragment;
import com.zj.syzs.fragment.MIGameGiftFragment;
import com.zj.syzs.fragment.MIGameInfoFragment;
import com.zj.syzs.utils.FragmentTabUtils;
import com.zj.syzs.utils.ImageDownLoader;
import com.zj.syzs.utils.JsonTask;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by ZJ on 2015/6/19 0019.
 */
public class MoneyInfoActivity extends ActionBarActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener {
    private ImageDownLoader task;
    private DisplayImageOptions options;
    private ViewPager money_info_viewpager;
    private ImageView money_info_icon;
    private TextView money_info_name, money_info_version, money_info_size, money_info_num;
    private Button money_info_download;
    private RadioGroup money_info_rgs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);
        setTitle("游戏详情");
        task = new ImageDownLoader(getApplicationContext());
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
        DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
        builder.showImageOnLoading(R.mipmap.ic_launcher);
        builder.showImageOnFail(R.mipmap.ic_launcher);
        builder.cacheInMemory(true).cacheOnDisk(true);
        builder.displayer(new RoundedBitmapDisplayer(20));
        options = builder.build();

        initView();
        initData();
    }

    private void initView() {
        List<Fragment> fragmentList = new ArrayList<Fragment>();

        fragmentList.add(new MIGameInfoFragment());
        fragmentList.add(new MIGameGiftFragment());
        fragmentList.add(new MICommentFragment());
        money_info_rgs = (RadioGroup) this.findViewById(R.id.money_info_rgs);
        FragmentTabUtils tabUtils = new FragmentTabUtils(fragmentList, money_info_rgs, getSupportFragmentManager(), R.id.money__fragment_container);
        tabUtils.setOnRgsExtraCheckedChangedListener(this);

        money_info_viewpager = (ViewPager) findViewById(R.id.money_info_viewpager);
        money_info_icon = (ImageView) findViewById(R.id.money_info_icon);
        money_info_name = (TextView) findViewById(R.id.money_info_name);
        money_info_version = (TextView) findViewById(R.id.money_info_version);
        money_info_size = (TextView) findViewById(R.id.money_info_size);
        money_info_num = (TextView) findViewById(R.id.money_info_num);
        money_info_download = (Button) findViewById(R.id.money_info_download);
    }

    private void initData() {
        HashMap<String, String> map = new HashMap<>();
        map.put("token", "a46f90a021aec5a011dbec7488a11a25");
        map.put("uid", "");
        map.put("compare", "dec135b59675a5a5a6a5ecd18bca81ab");
        map.put("id", getIntent().getStringExtra("id"));

        new JsonTask(map, new JsonTask.CallBackObject() {
            @Override
            public void loader(String json) {

            }
        }).execute(UrlConfig.MONEY_INFO_URL);
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }
}
